const mysql = require('mysql')

const { MYSQL_CONF } = require('../conf/db')

const con = mysql.createConnection(MYSQL_CONF)

// 开始连接
con.connect()
// 执行sql语句
function exec(sql) {
  return new Promise((resolve, reject) => {
    con.query(sql, (error, result) => {
      if (error) {
        console.log(error)
        reject(error)
        return
      }
      resolve(result)
    })
  })
}

module.exports = {
  exec
}
